package com.jzr.board.presenter.impl

import android.content.Context
import com.jzr.board.api.Api
import com.jzr.board.base.BasePresenter
import com.jzr.board.bean.BloodBean
import com.jzr.board.bean.NurseSchedulBean
import com.jzr.board.presenter.contract.EcgFragmentContract
import com.jzr.board.presenter.contract.NurseSchedulFragmentContract
import rx.Observer
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class EcgFragmentImpl : BasePresenter<EcgFragmentContract.View>(),
    EcgFragmentContract.Presenter<EcgFragmentContract.View> {



    override fun getOxymeterList(context: Context?, vararg s: String?) {
        showLoadingDialog(context)
        addSubscrebe(
            Api.getInstance()?.getOxymeterList(*s)
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribeOn(Schedulers.io())
                ?.unsubscribeOn(Schedulers.io())
                ?.subscribe(object : Observer<BloodBean?> {
                    override fun onCompleted() {}
                    override fun onError(e: Throwable) {
                        dismissLoadingDialog()
                        if (mView != null) mView?.showError("连接失败")
                    }

                    override fun onNext(t: BloodBean?) {
                        dismissLoadingDialog()
                        if (mView != null && t != null && t.code ==0) {
                            mView?.getOxymeterListSuccess(t)
                        } else {
                            mView?.showError(t?.message)
                        }
                    }
                })
        )
    }



}